import React, { Suspense } from "react";
import { Routes, Route } from "react-router-dom";
import { Spin } from "antd";
import router from "./router";
import "./App.css";

export default () => {
	// 加载动画
	function LoadView({ children }) {
		return (
			<Suspense
				fallback={
					<div
						style={{
							minHeight: "100vh",
							display: "flex",
							justifyContent: "center",
							alignItems: "center",
						}}
					>
						<Spin tip="玩命加载中..." />
					</div>
				}
			>
				{children}
			</Suspense>
		);
	}

	return (
		<Routes>
			{router.map((it) => (
				<Route
					key={it.path}
					path={it.path}
					element={<LoadView children={<it.component />} />}
				/>
			))}
		</Routes>
	);
};
